import { createSlice } from "@reduxjs/toolkit";

//修改是实时的
export const userSlice = createSlice({
    name: "user", //slicse 名字标识
    //初始状态值
    initialState: {
        userInfor: {
            id: '',
            ctime: '',
            account: '',
            userGroup: '',
            imgUrl: ''
        },
        stateFlag: false
    },
    // reducer:修改状态值 和 pinia的actions类似
    reducers: {
        changeInfor: (state, action) => {
            //action 为传递的参数 但是是一个对象 payload才为参数值
            state.userInfor = {...action.payload};
            // console.log(action.payload);
        },
        changeStateFlag: (state, action) => {
            state.stateFlag = !state.stateFlag;
        }
    }
})

export const {changeInfor,changeStateFlag} = userSlice.actions; //导出actions的函数
export default userSlice.reducer; //导出reducer